package com.server;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.Helper.*;

public class RefundServlet extends CustomerServlet
{
	private static final long serialVersionUID = 1L;
	private final String className = "Refund Servlet: ";
			
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException
	{
		String msg = null;
		ConnectDB();
		
		String firstName = req.getParameter("firstName");
		String lastName = req.getParameter("lastName");
		String seatID = req.getParameter("seatID");	
		String meal = req.getParameter("meal");
		String username = req.getParameter("username");
		String flightID = req.getParameter("flightID");
		String resID = req.getParameter("resID");
		
		float refundPrice;
		int refundPoint;
		
		req.setAttribute("firstName", firstName);
		req.setAttribute("lastName", lastName);
		req.setAttribute("seatID", seatID);
		req.setAttribute("meal", meal);
		req.setAttribute("username", username);
		req.setAttribute("flightID", flightID);
		req.setAttribute("resID", resID);
		
		try 
		{
			ReservationHelper.Setup(connection, username);
			ReservationInfo info = ReservationHelper.GetSelectedReservation(Integer.parseInt(resID));
			refundPrice = info.paidPrice;
			refundPoint = info.paidPoint;
			
			msg = "You will be refunded with " + refundPrice + " and " + refundPoint + " points";
			
			req.setAttribute("msg", msg);
			req.setAttribute("refundPrice", refundPrice);
			req.setAttribute("refundPoint", refundPoint);
			
			req.getRequestDispatcher("reservation/refund.jsp").forward(req, resp);
		} 
		catch (SQLException e) 
		{
			e.printStackTrace();
		}
	}

}

